<?php

namespace App\Admin\Forms;

use App\Models\Circle\WxCircle;
use App\Wen\Utils\CircleUtils;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\Cache;


class CircleForms extends Form implements LazyRenderable
{
    use LazyWidget;


    /**
     * 主题颜色.
     *
     * @var array
     */
    protected $status = [
        1 => '审核通过',
        2 => '驳回',
    ];

    /**
     * 处理表单请求.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        $id = $input['id'];
        $status = $input['circle_state'];
        $content = $input['content'];

        $circle = WxCircle::find($id);
        if($circle){
            CircleUtils::circle_pass($circle, $status, $content);
        }
        return $this->response()
            ->success('操作成功.')
            ->refresh();
    }

    /**
     * 构建表单.
     */
    public function form()
    {
        $this->hidden('id')->value($this->payload["id"]);
//        $this->radio('circle_state', "状态")->options($this->status)->default(1);
        $this->radio('circle_state', '状态')
            ->when(1, function (Form $form) {

            })
            ->when(2, function (Form $form) {
                $form->textarea('content', "驳回原因");
            })
            ->options([
                1 => '通过',
                2 => '驳回',

            ])->default(1);
    }

}
